import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//设计一学生类Student,
// 有私有成员变量（学号SNo,姓名Name,数学成绩Maths, 计算机基础成绩Computer,安卓成绩Android）,
// 有计算总分方法GetSumScore()和按总分排序方法sortBySum()。
public class Student implements Serializable {
  private Integer Sno;
  private String Name;
  private Double Math;
  private Double Computer;
  private Double Android;
  private Double totalScore;

  public Student() {
  }

  public Student(String name, Double math, Double computer, Double android) {
    Sno = Utility.getId();
    Name = name;
    Math = math;
    Computer = computer;
    Android = android;
  }

  /**
   * //所有学生自带的按总分排序方法sortBySum()
   *
   * @param students
   * @return 结果集
   */
  public static List<Student> sortBySum(List<Student> students) {
    //自定义排序
//    Collections.sort() 方法会改变arraylist本身，所有复制一份
    ArrayList<Student> templist = new ArrayList<>(students);
    Collections.sort(templist, new Comparator<Student>() {
      @Override
      public int compare(Student o1, Student o2) {
        return o1.getTotalScore() - o2.getTotalScore() > 0 ? -1 : 1;
      }
    });
    return templist;
  }

  //计算总分的方法.
  public Double getTotalScore() {
    totalScore = this.Android + this.Computer + this.Math;
    return totalScore;
  }

  public void setTotalScore(Double totalScore) {
    this.totalScore = totalScore;
  }

  public Integer getSno() {
    return Sno;
  }

  public void setSno(Integer sno) {
    Sno = sno;
  }

  public String getName() {
    return Name;
  }

  public void setName(String name) {
    Name = name;
  }

  public Double getMath() {
    return Math;
  }

  public void setMath(Double math) {
    Math = math;
  }

  public Double getComputer() {
    return Computer;
  }

  public void setComputer(Double computer) {
    Computer = computer;
  }

  public Double getAndroid() {
    return Android;
  }

  public void setAndroid(Double android) {
    Android = android;
  }

  @Override
  public String toString() {
    return
        Sno +
            "\t" + Name +
            "\t" + Math +
            "\t" + Computer +
            "\t" + Android
        ;
  }
}
